package com.tdtxdcxm.ruralcommunity.slice;

import com.tdtxdcxm.ruralcommunity.ResourceTable;
import com.tdtxdcxm.ruralcommunity.appruntime.DataCenterControl;
import com.tdtxdcxm.ruralcommunity.myutils.MyTools;
import com.tdtxdcxm.ruralcommunity.providers.LCProviderForNormal;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

public class PeopleListSlice extends AbilitySlice {
    private Button usercontent_backbut;
    private ListContainer usercontent_lc;

    private void initListContainer(ListContainer listContainer,String listContainerName,AbilitySlice slice){
        if(listContainer == null){
            return;
        }
        listContainer.setName(listContainerName);
        LCProviderForNormal lcProviderForNormal = new LCProviderForNormal(DataCenterControl.people_listcontainer_list,this);
        listContainer.setItemProvider(lcProviderForNormal);
        DataCenterControl.peopleListContainerProvider = lcProviderForNormal;

        listContainer.setItemLongClickedListener(new ListContainer.ItemLongClickedListener() {
            @Override
            public boolean onItemLongClicked(ListContainer listContainer, Component component, int i, long l) {
                DirectionalLayout directionalLayout= ((DirectionalLayout)component);
                Text text = (Text)directionalLayout.getComponentAt(0);
                if(text.getText().endsWith("[关注]")){
                    MyTools.commonDialogRemoveShow("关注提示"
                            ,"是否关注？"
                            ,component
                            ,-1
                            ,PeopleListSlice.this
                            ,"follow");
                }
                else if(text.getText().endsWith("[已关注]")){
                    MyTools.commonDialogRemoveShow("取消关注提示"
                                                ,"是否取消关注？"
                                                ,component
                                                ,-1
                                                ,PeopleListSlice.this
                                                ,"unfollow");
                }
                return true;
            }
        });
    }

    private void initPLSComponents(){
        usercontent_backbut = (Button) findComponentById(ResourceTable.Id_usercontent_backbut);
        usercontent_lc = (ListContainer) findComponentById(ResourceTable.Id_usercontent_lc);

        usercontent_backbut.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                DataCenterControl.people_listcontainer_list.clear();
                terminate();
            }
        });
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_usercontent_item_listcontainer);
        initPLSComponents();
        initListContainer(usercontent_lc,"peoplelc",this);
        MyTools.UpDataSearchUserInfo(this,DataCenterControl.userName,intent.getStringParam("objectname"));
    }

    @Override
    protected void onActive() {
        super.onActive();
    }

    @Override
    protected void onInactive() {
        super.onInactive();
    }

    @Override
    protected void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    protected void onBackground() {
        super.onBackground();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }
}
